<template>
	<view class="mainpadding" style="padding-bottom: 150rpx;" v-if="pageShow">
		<view class="flexleft">
			<view class="labletext xiaohuang margin_right" v-if="dataAll.task_category_id!=1">{{dataAll.taskcategory.name}}/{{dataAll.carattr.name}}</view>
			<view class="labletext xiaohuang margin_right" v-if="dataAll.task_category_id==1">其他</view>
			<!-- 状态:1=待领取,2=平台待指定,3=进行中,4=待审核,5=已完成，6任务终止 -->
			<view class="titletext hei_text bold" v-if="dataAll.status==1">待领取</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==2">待指定</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==3">进行中</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==4">待审核</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==5">已完成</view>
			<view class="titletext hei_text bold" v-if="dataAll.status==6">任务终止</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween xiahuaxian">
				<view class="titletext hei_text bold">{{dataAll.tasktime_text}}</view>
				<view class="xiaohong bold titletext">{{dataAll.score}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.start_address">
				<view class="xiankuan" style="width: 500rpx;">
					<text class="lvdian margin_right2"></text>
					<text class="xiaolv main_size margin_right2">距你{{returnKmUnit(Number(dataAll.distance1))}}</text>
					<text class="xiaohei main_size margin_right2">{{dataAll.start_address}}</text>
				</view>
				<view class="daohang" @click="openmap(1,dataAll)"></view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.end_address">
				<view class="xiankuan" style="width: 500rpx;">
					<text class="huangdian margin_right2"></text>
					<text class="xiaohuang main_size margin_right2">距你{{returnKmUnit(Number(dataAll.distance2))}}</text>
					<text class="xiaohei main_size margin_right2">{{dataAll.end_address}}</text>
				</view>
				<view class="daohang" @click="openmap(2,dataAll)"></view>
			</view>
			<view class="xiankuan margin_top" style="width: 500rpx;">
				<text class="landian margin_right2"></text>
				<text class="xiaolan main_size margin_right2">{{dataAll.name}}</text>
				<text class="xiaohei main_size margin_right2" v-show="dataAll.task_category_id!=1">航班/车次：{{dataAll.carno}}</text>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius" v-if="dataAll.taskitem.length">
			<view class="titletext hei_text bold">任务要求</view>
			<view class="" v-for="ite in dataAll.taskitem" :key="ite.id">
				<view class="main_size xiaohui margin_top">{{ite.name}}</view>
				<view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top2" v-for="(it,index) in ite.images_text">
						<view class="listleftimg">
							<image class="listleftimg radius" :src="it" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius" v-if="dataAll.user_id">
			<view class="titletext hei_text bold">司机信息</view>
			<view class="main_size xiaohui margin_top">姓名：{{dataAll.user.username}}</view>
			<view class="main_size xiaohui margin_top" @click="callphone(dataAll.user.mobile)">
				电话：{{dataAll.user.mobile}}</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween">
				<view class="main_size xiaohei bold">订单编号</view>
				<view class="main_size xiaohui">{{dataAll.order_no}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="main_size xiaohei bold">收益</view>
				<view class="main_size xiaohuang">{{dataAll.score}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="main_size xiaohei bold">任务时间</view>
				<view class="main_size xiaohui">{{dataAll.tasktime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.jdtime_text">
				<view class="main_size xiaohei bold">接单时间</view>
				<view class="main_size xiaohui">{{dataAll.jdtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.status==4 || dataAll.status==5">
				<view class="main_size xiaohei bold">审核上传</view>
				<view class="main_size xiaohui">{{dataAll.applyuploadtime_text}}</view>
			</view>
			<view class="flexleft flex_wrap" v-if="dataAll.status==4 || dataAll.status==5">
				<view class="itemimgBox flexcenter margin_top" v-for="(it,index) in dataAll.apply_images_text"
					@click="lbtpriview(index,dataAll.apply_images_text)">
					<view class="listleftimg">
						<image class="listleftimg radius" :src="it" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding2 flex_wrap flexright ffffff">
			<view class="qhbtn flexcenter padding_top2 margin_left1"
				@click.stop="jumpdetail('/pages_mypage/renwubeizhu?id=',dataAll.id)">任务备注</view>
			<view class="qhbtn padding_top2 flexcenter margin_left1"
				@click.stop="jumpdetail('/pages_mypage/renwuyq?id=',dataAll.id)">任务要求</view>
			<view class="qhbtn  padding_top2 flexcenter margin_left1"
				@click.stop="jumpdetail('/pages_mypage/tianjiarenwu?id=',dataAll.id)">编辑</view>
			<view class="qhhbtn padding_top2 flexcenter margin_left1" @click.stop="currentid=dataAll.id;showModal('是否确认删除任务？')">删除
			</view>
			<view class="qhrbtn padding_top2 flexcenter margin_left1" v-if="dataAll.status==0"
				@click.stop="currentid=dataAll.id;showModal('是否确认任务？')">确认任务</view>
			<view class="qhrbtn padding_top2 flexcenter margin_left1" v-if="dataAll.status<3"
				@click.stop="jumpdetail('/pages_mypage/zhipaisiji?id=',dataAll.id)">指派司机</view>
			<view class="qhbtn padding_top2 flexcenter margin_left1" v-if="dataAll.status==3"
				@click.stop="jumpdetail('/pages_mypage/zhipaisiji?id=',dataAll.id)">更换司机</view>
			<view class="qhrbtn padding_top2 flexcenter margin_left1" v-if="dataAll.status!=6"
				@click.stop="currentid=dataAll.id;showModal('是否确认终止任务？')">终止任务</view>
			<view class="qhrbtn padding_top2 flexcenter margin_left1" v-if="dataAll.status==4"
				@click.stop="currentid=dataAll.id;showModal('是否确认审核任务？')">审核任务</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				modal: {
					modalShow: false,
					title: "",
				},
				images_text: [],
				images: [],
				show: false,
				lat: "",
				lng: "",
				dataAll: {},
				pageShow: false,
				listid: "",
				currentid: "",
				isLoad: false
			}
		},
		onLoad(options) {
			this.listid = options.id
			// #ifdef APP-PLUS
			this.getLocation()
			// #endif
			// #ifdef H5
			this.getDetail()
			// #endif
		},
		onShow() {
			if (this.isLoad) {
				this.getDetail()
			}
		},
		methods: {
			showModal(val) {
				this.modal.title = val
				this.modal.modalShow = true
			},
			modalSure() {
				if (this.modal.title == "是否确认终止任务？") {
					this.zhongzhiorder()
				} else if (this.modal.title == "是否确认任务？") {
					this.querenorder()
				} else if (this.modal.title == "是否确认审核任务？") {
					this.shenheorder()
				} else if (this.modal.title == "是否确认删除任务？") {
					this.shanchuorder()
				}
				this.modalcancel()
			},
			modalcancel() {
				this.modal.modalShow = false
			},
			zhongzhiorder() { //终止任务
				httpRequest.request('/api/admintask/stopTask', 'GET', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.getDetail()
					}
				})
			},
			querenorder() { //确认任务
				httpRequest.request('/api/admintask/sureTask', 'GET', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.getDetail()
					}
				})
			},
			shenheorder() { //审核任务
				httpRequest.request('/api/admintask/applyTask', 'GET', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.getDetail()
					}
				})
			},
			shanchuorder() { //删除任务
				httpRequest.request('/api/admintask/delTask', 'GET', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			getLocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						console.log(res, "获取定位成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getDetail()
					},
					fail(err) {
						uni.hideLoading()
					}
				});
			},
			getDetail() {
				httpRequest.request('/api/taskcl/taskDetail', 'GET', {
					id: this.listid,
					lat: this.lat,
					lng: this.lng,
				}).then(res => {
					this.isLoad = true
					this.dataAll = res.data
					this.pageShow = true
				})
			},

			openmap(val, item) {
				if (val == 1) {
					uni.openLocation({
						latitude: Number(item.start_latitude), //即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
						longitude: Number(item.start_longitude), //即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
						name: item.start_address, //即将传到高德或腾讯地图的店铺名称
						address: item.start_address, //即将传到高德或腾讯地图的详细地址
						scale: 18
					})
				} else {
					uni.openLocation({
						latitude: Number(item.end_latitude), //即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
						longitude: Number(item.end_longitude), //即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
						name: item.end_address, //即将传到高德或腾讯地图的店铺名称
						address: item.end_address, //即将传到高德或腾讯地图的详细地址
						scale: 18
					})
				}

			}
		}
	}
</script>

<style>
	.padding_top2{
		margin-top: 20rpx;
	}
	.qhrbtn {
		border-radius: 12rpx;
		background-color: #FF8505;
		font-weight: 500;
		font-size: 26rpx;
		padding: 15rpx 30rpx;
		color: #FFf;
	}

	.qhhbtn {
		border-radius: 12rpx;
		background-color: #ff0000;
		font-weight: 500;
		font-size: 26rpx;
		padding: 15rpx 30rpx;
		color: #FFf;
	}

	.qhbtn {
		border-radius: 12rpx;
		background-color: #fff3e6;
		font-weight: 500;
		font-size: 26rpx;
		padding: 15rpx 30rpx;
		color: #FF8505;
	}

	.listleftimg {
		width: 160rpx;
		height: 160rpx;
		min-width: 160rpx;
		position: relative;
	}
</style>